package cn.yunyichina.provider.reservation.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.reservation.dao.ConsoleUserDao;
import cn.yunyichina.provider.reservation.entity.ConsoleUser;
import cn.yunyichina.provider.reservation.service.ConsoleUserService;

import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by Lullaby on 2016/8/19.
 */
@Service
public class ConsoleUserServiceImpl implements ConsoleUserService {

    @Resource
    private ConsoleUserDao consoleUserDao;

    public Response getConsoleUser(String params, String sessionId) {
        ConsoleUser userParam = JSON.parseObject(params, ConsoleUser.class);
        List<ConsoleUser> userList = consoleUserDao.select(userParam);
        ConsoleUser user = null;
        if (!CollectionUtils.isEmpty(userList)) {
            user = userList.get(0);
        }
        Response response = new Response();
        response.setResult(JSON.toJSONString(user));
        return response;
    }

    public Response listConsoleUser() {
        Response response = new Response();
        List<ConsoleUser> userList = consoleUserDao.select();
        response.setResult(JSON.toJSONString(userList));
        return response;
    }

}
